package logic

import (
	"context"
	"errors"
	"work/model/mysql"

	"work/workrpc/internal/svc"
	"work/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoryAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoryAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoryAddLogic {
	return &StoryAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StoryAddLogic) StoryAdd(in *workrpc.StoryAddRequest) (*workrpc.StoryAddResponse, error) {
	// todo: add your logic here and delete this line
	story := mysql.Story{
		Title: in.Title,
		Typer: in.Typer,
		Label: in.Label,
		Brief: in.Brief,
	}
	err := story.StoryAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}
	return &workrpc.StoryAddResponse{
		StoryId: int64(story.ID),
	}, nil
}
